package com.itheima.text;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Test1 {
    public static void main(String[] args) throws IOException {
        //需求：把《出师表》的文章顺序进行恢复到一个新文件中。
        BufferedReader br = new BufferedReader(new FileReader("day29-code\\csb.txt"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("day29-code\\result.txt"));

        String s;
        ArrayList<String> list = new ArrayList<>();
        while((s=br.readLine())!=null){
            list.add(s);
        }

        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int i1 = Integer.parseInt(o1.split("\\.")[0]);
                int i2 = Integer.parseInt(o2.split("\\.")[0]);
                return i1-i2;
            }
        });
        // System.out.println(list);
        for (String s1 : list) {
            bw.write(s1);
            bw.newLine();
        }
        bw.close();
        br.close();
    }
}
